package com.qyhl.webtv.module_news.news.jlnews.multi.fragment;


import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.entity.news.JLMultiNewsListBean;
import com.qyhl.webtv.module_news.common.NewsUrl;

import java.util.List;

public class JLMultiNewsItemModel implements JLMultiNewsItemContract.JLMultiNewsItemModel {
    private JLMultiNewsItemPresenter mPresenter;

    JLMultiNewsItemModel(JLMultiNewsItemPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getList(int cityId) {
        EasyHttp.get(NewsUrl.JL_NEWS_MULTI_LIST)
                .params("cityId", cityId + "")
                .execute(new SimpleCallBack<List<JLMultiNewsListBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError(0);
                        } else {
                            mPresenter.setError(1);
                        }
                    }

                    @Override
                    public void onSuccess(List<JLMultiNewsListBean> jlMultiNewsListBeans) {
                        if (jlMultiNewsListBeans != null && jlMultiNewsListBeans.size() > 0) {
                            mPresenter.setList(jlMultiNewsListBeans);
                        } else {
                            mPresenter.setError(0);
                        }
                    }
                });

    }
}
